package com.hefu.virtuallife.utils;


import com.hefu.virtuallife.App;
import com.hefu.virtuallife.R;
import com.hefu.virtuallife.bean.DaoSession;
import com.hefu.virtuallife.bean.SmartHomeBean;
import com.hefu.virtuallife.bean.SmartHomeBeanDao;
import com.hefu.virtuallife.constant.RoomType;
import com.hefu.virtuallife.constant.SmartHomeType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by pc on 2018/7/24.
 */

public class SmartDataUtils {

    private static HashMap<Integer, Integer> resMap = new HashMap<>();
    private static HashMap<String, Integer> resMap1 = new HashMap<>();

    public static void fillData(){

        resMap1.put("wifi", R.drawable.wifi);
        resMap1.put("冰箱", R.drawable.refrigerator);
        resMap1.put("窗帘", R.drawable.curtain);
        resMap1.put("电脑", R.drawable.computer);
        resMap1.put("电视", R.drawable.tv);
        resMap1.put("咖啡机", R.drawable.coffeemachine);
        resMap1.put("烤箱", R.drawable.oven);
        resMap1.put("空调", R.drawable.airconditioning);
        resMap1.put("空调通风", R.drawable.airconditioning_ventilation);
        resMap1.put("热水器", R.drawable.waterheater);
        resMap1.put("扫地机", R.drawable.sweepingrobot);
        resMap1.put("灯", R.drawable.lamp);
        resMap1.put("投影", R.drawable.projection);
        resMap1.put("洗衣机", R.drawable.washingmachine);
        resMap1.put("音乐", R.drawable.music);

        resMap.put(SmartHomeType.WIFI, R.drawable.wifi);
        resMap.put(SmartHomeType.REFRIGERATOR, R.drawable.refrigerator);
        resMap.put(SmartHomeType.CURTAIN, R.drawable.curtain);
        resMap.put(SmartHomeType.COMPUTER, R.drawable.computer);
        resMap.put(SmartHomeType.TV, R.drawable.tv);
        resMap.put(SmartHomeType.COFFEEMACHINE, R.drawable.coffeemachine);
        resMap.put(SmartHomeType.OVEN, R.drawable.oven);
        resMap.put(SmartHomeType.AIRCONDITIONING, R.drawable.airconditioning);
        resMap.put(SmartHomeType.AIRCONDITIONING_VENTILATION, R.drawable.airconditioning_ventilation);
        resMap.put(SmartHomeType.WATERHEATER, R.drawable.waterheater);
        resMap.put(SmartHomeType.SWEEPINGROBOT, R.drawable.sweepingrobot);
        resMap.put(SmartHomeType.LAMP, R.drawable.lamp);
        resMap.put(SmartHomeType.PROJECTION, R.drawable.projection);
        resMap.put(SmartHomeType.WASHINGMACHINE, R.drawable.washingmachine);
        resMap.put(SmartHomeType.MUSIC, R.drawable.music);



        DaoSession daoSession = App.getDaoIns();
        daoSession.deleteAll(SmartHomeBean.class);
        SmartHomeBeanDao smartHomeDao = daoSession.getSmartHomeBeanDao();
        //结婚纪念日

        smartHomeDao.insert(new SmartHomeBean(null, "wifi", false, SmartHomeType.WIFI, RoomType.LIVINGROOM, "结婚纪念日"));
        smartHomeDao.insert(new SmartHomeBean(null, "热水器", false, SmartHomeType.WATERHEATER, RoomType.BATHROOM, "结婚纪念日"));
        smartHomeDao.insert(new SmartHomeBean(null, "烤箱", false, SmartHomeType.OVEN, RoomType.KITCHEN, "结婚纪念日"));
        smartHomeDao.insert(new SmartHomeBean(null, "空调通风",false, SmartHomeType.AIRCONDITIONING_VENTILATION, RoomType.LIVINGROOM, "结婚纪念日"));
        smartHomeDao.insert(new SmartHomeBean(null, "扫地机", false, SmartHomeType.SWEEPINGROBOT, RoomType.LIVINGROOM, "结婚纪念日"));
        smartHomeDao.insert(new SmartHomeBean(null, "冰箱", false, SmartHomeType.REFRIGERATOR, RoomType.KITCHEN, "结婚纪念日"));


        //回家场景
        smartHomeDao.insert(new SmartHomeBean(null, "电视", false, SmartHomeType.TV, RoomType.LIVINGROOM, "回家"));
        smartHomeDao.insert(new SmartHomeBean(null, "灯", false, SmartHomeType.LAMP, RoomType.LIVINGROOM, "回家"));
        smartHomeDao.insert(new SmartHomeBean(null, "咖啡机", false, SmartHomeType.COFFEEMACHINE, RoomType.KITCHEN, "回家"));
        smartHomeDao.insert(new SmartHomeBean(null, "窗帘",false, SmartHomeType.CURTAIN, RoomType.LIVINGROOM, "回家"));
        smartHomeDao.insert(new SmartHomeBean(null, "洗衣机",false, SmartHomeType.WASHINGMACHINE, RoomType.KITCHEN, "回家"));

        //聚会
        smartHomeDao.insert(new SmartHomeBean(null, "音乐",false, SmartHomeType.MUSIC, RoomType.LIVINGROOM, "聚会"));
        smartHomeDao.insert(new SmartHomeBean(null, "空调",false, SmartHomeType.AIRCONDITIONING, RoomType.LIVINGROOM, "聚会"));

        //开会
        smartHomeDao.insert(new SmartHomeBean(null, "电脑",false, SmartHomeType.COMPUTER, RoomType.STUDYROOM, "开会"));
        smartHomeDao.insert(new SmartHomeBean(null, "空调",false, SmartHomeType.AIRCONDITIONING, RoomType.STUDYROOM, "开会"));
        smartHomeDao.insert(new SmartHomeBean(null, "投影",false, SmartHomeType.PROJECTION, RoomType.STUDYROOM, "开会"));

        //其它
        smartHomeDao.insert(new SmartHomeBean(null, "灯",false, SmartHomeType.LAMP, RoomType.MASTERBEDROOM, ""));
        smartHomeDao.insert(new SmartHomeBean(null, "窗帘",false, SmartHomeType.CURTAIN, RoomType.MASTERBEDROOM, ""));
        smartHomeDao.insert(new SmartHomeBean(null, "电视",false, SmartHomeType.TV, RoomType.MASTERBEDROOM, ""));
        smartHomeDao.insert(new SmartHomeBean(null, "电脑",false, SmartHomeType.COMPUTER, RoomType.MASTERBEDROOM, ""));
        smartHomeDao.insert(new SmartHomeBean(null, "空调",false, SmartHomeType.AIRCONDITIONING, RoomType.MASTERBEDROOM, ""));

    }

    public static int getRes(int type){
        return resMap.get(type);
    }

    public static int getResByName(String name){
        return resMap1.get(name);
    }


    
    //查询场景设备
    public static List<SmartHomeBean> querySceneEquip(String scene){
        List<SmartHomeBean> list = App.getDaoIns().getSmartHomeBeanDao().queryBuilder().where(
                SmartHomeBeanDao.Properties.Scene.eq(scene)).list();
        return list;
    }

    //查询房间设备
    public static List<SmartHomeBean> queryRoomEquip(String roomType){
        List<SmartHomeBean> list = App.getDaoIns().getSmartHomeBeanDao().queryBuilder().where(
                SmartHomeBeanDao.Properties.RoomType.eq(roomType)).list();
        return list;
    }


    public static void update(SmartHomeBean bean){
        App.getDaoIns().getSmartHomeBeanDao().update(bean);
    }

    //更新设备状态
    public static void update(List<SmartHomeBean> list){
        App.getDaoIns().getSmartHomeBeanDao().updateInTx(list);
       //App.getDaoIns().getSmartHomeBeanDao().update(list);
    }


}
